﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace ParboiledSharp.lang.roboline.context
{
    class ExecContext
    {
        private ArrayList _stack = new ArrayList(1000);

        public object Peek(int index) {
            return _stack[_stack.Count - 1 - index];
        }

        public object Peek()
        {
            return _stack[_stack.Count - 1];
        }

        public void SwapStackElements(int index1, int index2) { 
            index1=_stack.Count-1-index1;
            index2=_stack.Count-1-index2;
            object t = _stack[index1];
            _stack[index1] = _stack[index2];
            _stack[index2] = t;
        }

        public object Pop(int index)
        {
            int last_index = _stack.Count - 1;
            object o= _stack[last_index - index];
            _stack.RemoveAt(last_index-index);
            return o;
        }

        public object Pop()
        {
            int last_index = _stack.Count - 1;
            object o = _stack[last_index];
            _stack.RemoveAt(last_index);
            return o;
        }

        public void Push(object value) {
            _stack.Add(value);
        }
    }
}
